import Vue from 'vue'
import Router from 'vue-router'
import viewCatalog from "../view/catalog/viewCatalog";
import viewProduct from "../view/catalog/viewProduct";
import viewSearch from "../view/catalog/viewSearch";
import viewItem from "../view/catalog/viewItem";
import index from "../view/index"
import about from "../view/common/about";
import contact from "../view/common/contact";
import viewOrders from "../view/order/viewOrders";
import checkOrder from "../view/order/checkOrder";
import viewNewOrder from "../view/order/viewNewOrder";
import cart from "../view/cart/cart";
import user from "../view/user/user";
import header from '@/components/header'
import footer from '@/components/footer'
import myAccount from "../view/user/myAccount";

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index
    },
    {
      path: '/catalog/viewCatalog',
      name: 'viewCatalog',
      component: viewCatalog

    },
    {
      path: '/common/about',
      name: 'about',
      component: about
    },
    {
      path: '/common/contact',
      name: 'contact',
      component: contact
    },
    {
      path: '/user',
      name: 'userIndex',
      component: index,
      redirect: to => {

        console.log("to : " + to.name)

        if (to.name === 'userIndex'){
          let alreadyLogin;
          let nowAccount = sessionStorage.getItem("nowUsername");
          alreadyLogin = nowAccount != null;
          return{
            name:alreadyLogin?'myAccount':'user'
          }
        }
      }
    },
    {
      path: '/user/user',
      name: 'user',
      component:user
    },
    {
      path: '/user/myAccount',
      name: 'myAccount',
      component:myAccount
    },
    {
      path: '/order/viewOrders',
      name: 'viewOrders',
      component: viewOrders
    },
    {
      path: '/order/checkOrder',
      name: 'checkOrder',
      component: checkOrder
    },
    {
      path: '/order/viewNewOrder',
      name: 'viewNewOrder',
      component: viewNewOrder
    },
    {
      path: '/cart/cart',
      name: 'cart',
      component: cart
    },
    {
      path: '/user/user',
      name: 'user',
      component: user
    },
    {
      path: '/catalog/viewProduct',
      name: 'viewProduct',
      component:  viewProduct
    },
    {
      path: '/catalog/viewSearch',
      name: 'viewSearch',
      component: viewSearch
    },
    {
      path: '/catalog/viewItem',
      name: 'viewItem',
      component: viewItem
    }
  ]
})
